//相当于页面的入口函数 进入页面就执行
function viewRoom() {
    //发送ajax获取值
    $.ajax({
        url: "../../room/all",
        type: "get",
        dataType: "json",
        success: function (data) {
            var content = "";
            for (var i = 0; i < data.length; i++) {
                room = data[i];

                content += '<div class="layui-col-xs2">' +
                    '<div class="grid-demo grid-demo-bg1">';
                if (room.status == 0) {
                    content += '<button type="button" class="layui-btn" onclick="b1(' + room.room_id + ')" >' + room.roomnum + '房:可入住</button>';
                } else if (room.status == 1) {
                    content += ' <button type="button" class="layui-btn layui-btn-danger"onclick="b1(' + room.room_id + ')" >' + room.roomnum + '房:已入住</button>';
                } else if (room.status == 2) {
                    content += '<button type="button" class="layui-btn layui-btn-warm" onclick="b1(' + room.room_id + ')" >' + room.roomnum + '房:维修中</button>';
                } else if (room.status == 3) {
                    content += '<button type="button" class="layui-btn layui-btn-normal" onclick="b1(' + room.room_id + ')" >' + room.roomnum + '房:已预订</button>';
                }
                content += ' </div>' +
                    '</div>';

            }
            $("#viewRoom").html(content);
        }
    });
}
//调用该入口函数
viewRoom();

function b1(room_id) {
    layui.use('layer', function () {
        var layer = layui.layer;
        //iframe层-父子操作
        b1s = layer.open({
            title: "父子页面标题",
            type: 2,
            area: ['70%', '60%'],
            scrollbar: true, //默认：true,默认允许浏览器滚动
            maxmin: true,
            content: '../room/loadRoom.html',
            success: function (layero, index) {
                var iframe = window['layui-layer-iframe' + index];
                iframe.child(room_id)
            }
        });
    });
}
